<!-- 文件名：product_list.html -->
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head><title>商品列表</title></head>
<body>
<table border="1px">
  <tr>
    <th>商品名称</th>
    <th>价格</th>
    <th>图片</th>
    <th>操作</th>
  </tr>
  <tr th:each="p : ${products}">
    <td th:text="${p.name}"></td>
    <td th:text="${p.price}"></td>
    <td>
      <img th:if="${p.imagePath != null}" th:src="@{${p.imagePath}}" width="100"/>
    </td>
    <td>
      <a th:href="@{'/cart/add?productId=' + ${p.id} + '&username=' + ${user.username}}">加入购物车</a>
      <form action="/upload" method="post" enctype="multipart/form-data">
        <input type="file" name="file"/>
        <input type="hidden" name="productId" th:value="${p.id}" />
        <button type="submit">上传图片</button>
      </form>
    </td>
  </tr>
</table>

<br>
<!--<a href="/products/new">添加新商品</a> |-->
<!--<a href="/cart">购物车</a> |-->
<!--<a href="/orders">订单列表</a> |-->
<!--<a href="/products/bought">购买过的商品</a>-->
<a th:href="@{'/products/new?username=' + ${user.username}}">添加新商品</a> |
<a href="/cart" th:href="@{'/cart?username=' + ${user.username} }">购物车</a> |
<a href="/orders" th:href="@{'/orders?username=' + ${user.username} }">订单列表</a> |
<a href="/purchased" th:href="@{'/purchased?username=' + ${user.username} }">购买过的商品</a>
</body>
</html>
